<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Database\Eloquent\Model as Eloquent;

class ModelView
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $model;

    public $tag;

    public $expireIn =60 * 60 * 2;  // 2小时有效期

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct(Eloquent $model, $tag, $expireIn = 0)
    {
        $this->model = $model;
        $this->tag = $tag;
        $this->expireIn = $expireIn ? : $this->expireIn;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('channel-name');
    }
}
